home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.output.drawable;
- import sub_arctic.output.shadow_drawable;
- import sub_arctic.input.event;
- import java.awt.Dimension;
- import java.awt.Point;
-
- /**
- * Specialized subclass of drag_container that casts a shadow under the
- * objects it drags while they are being dragged. This is done by drawing
- * the child objects twice (when they are being dragged), once as a shadow
- * using a shadow_drawable drawable object, and then again normally on top of
- * that.
- *
- * @see sub_arctic.lib.drag_container
- * @see sub_arctic.lib.shadow_caster
- * @see sub_arctic.output.shadow_drawable
- *
- * @author Scott Hudson
- */
- public class shadow_drag_container extends drag_container {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do we do expensive but realistic drawing of shadows for images, or do
- * we just do their bounding rectangle? Default is to be cheap about it.
- */
- protected boolean _expensive_draw = false;
-
- /**
- * Are currently doing expensive but realistic drawing shadows for images,
- * or do are we just drawing their bounding rectangle?
- * @return boolean indicating if we are drawing in expensive mode.
- */
- public boolean expensive_draw() {return _expensive_draw;}
-
- /** Set whether we draw image shadows realistically, but expensively (slow),
- * or just draw their bounding rectangles (fast).
- *
- * @param v true if we draw slow but realistic images, false if we draw fast
- */
- public void set_expensive_draw(boolean v)
- {
- if (v != _expensive_draw)
- {
- _expensive_draw = v;
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Full constructor.
- *
- * @param x x position of the container within its parent's coords
- * @param y y position of the container within its parent's coords
- * @param shad_x_offset offset of shadow in x direction
- * @param shad_y_offset offset of shadow in y direction
- */
- public shadow_drag_container(int x, int y, int shad_x_off, int shad_y_off)
- {
- super(x,y,false);
- _x_offset = 0; _y_offset = 0;
- set_offset(shad_x_off, shad_y_off);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constructor with default shadow offsets.
- *
- * @param x x position of the container within its parent's coords
- * @param y y position of the container within its parent's coords
- */
- public shadow_drag_container(int x, int y)
- {
- this(x,y, shadow_drawable.default_off_x, shadow_drawable.default_off_y);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** X offset for shadow */
- protected int _x_offset;
-
- /**
- * X offset for shadow.
- * @return int the x offset for the shadow.
- */
- public int x_offset() {return _x_offset;}
-
- /**
- * Set x offset for shadow.
- * @param xoff the new x offset
- */
- public void set_x_offset(int xoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _x_offset = xoff;
-
- /* set shrink_wrap border to be 2 larger than the shadow */
- set_border(Math.max(_x_offset,_y_offset)+2);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Y offset for shadow */
- protected int _y_offset;
-
- /**
- * Y offset for shadow.
- * @return int the y offset for the shadow.
- */
- public int y_offset() {return _y_offset;}
-
- /**
- * Set y offset for shadow.
- * @param yoff the new y offset
- */
- public void set_y_offset(int yoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _y_offset = yoff;
-
- /* set shrink_wrap border to be 2 larger than the shadow */
- set_border(Math.max(_x_offset,_y_offset)+2);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Set offset for shadow
- *
- * @param xoff the new x offset
- * @param yoff the new y offset
- */
- public void set_offset(int xoff, int yoff)
- {
- /* need a redraw after this */
- damage_self();
-
- _x_offset = xoff;
- _y_offset = yoff;
-
- /* set shrink_wrap border to be 2 larger than the shadow */
- set_border(Math.max(_x_offset,_y_offset)+2);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle the start of a drag to the object.
- *
- * @param evt the event starting the drag
- * @param x_pos x position of the drag (in parent's coordinates)
- * @param y_pos y position of the drag (in parent's coordinates)
- * @param grab_x x position where object was grabbed (in local coords)
- * @param grab_y y position where object was grabbed (in local coords)
- * @param user_info info object (originally passed to the focus agent)
- * @return whether the input was consumed/accepted
- */
- public boolean drag_start(
- event evt,
- int x_pos, int y_pos,
- int grab_x, int grab_y,
- Object user_info)
- {
- boolean result;
-
- /* let super class do the work */
- result = super.drag_start(evt, x_pos, y_pos, grab_x, grab_y, user_info);
-
- /* move the object over to simulate a lift off of the surface */
- set_pos(x_pos-x_offset(), y_pos-y_offset());
-
- return result;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle a movement during a drag. Here we set our position (offset by
- * the shadow size) to follow the drag location.
- *
- * @param evt the event starting the drag
- * @param x_pos x position of the drag (in parent's coordinates)
- * @param y_pos y position of the drag (in parent's coordinates)
- * @param st_x starting x position of the drag (in parent's coords)
- * @param st_y starting y position of the drag (in parent's coords)
- * @param grab_x x position where object was grabbed (in local coords)
- * @param grab_y y position where object was grabbed (in local coords)
- * @param user_info info object (originally passed to the focus agent)
- * @return whether the input was consumed/accepted
- */
- public boolean drag_feedback(
- event evt,
- int x_pos, int y_pos,
- int st_x, int st_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- /* move our position */
- set_pos(x_pos - x_offset(), y_pos - y_offset());
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle input corresponding to the end of a drag.
- * @param evt the event starting the drag
- * @param x_pos x position of the drag (in parent's coordinates)
- * @param y_pos y position of the drag (in parent's coordinates)
- * @param st_x starting x position of the drag (in parent's coords)
- * @param st_y starting y position of the drag (in parent's coords)
- * @param grab_x x position where object was grabbed (in local coords)
- * @param grab_y y position where object was grabbed (in local coords)
- * @param user_info info object (originally passed to the focus agent)
- * @return whether the input was consumed/accepted
- */
- public boolean drag_end(
- event evt,
- int x_pos, int y_pos,
- int start_x, int start_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- boolean result;
-
- /* let super class do the work */
- result = super.drag_end(
- evt, x_pos, y_pos, start_x, start_y, grab_x, grab_y, user_info);
-
- /* move back to normal to simulate touch down */
- set_pos(x_pos, y_pos);
-
- return result;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw self. If we are not being dragged, we just draw our children.
- * If we are, we draw our children twice, once in shadow offset by
- * a small translation, then again in normal colors.
- *
- * @param d the drawable object we are to draw on.
- */
- protected void draw_self_local(drawable d)
- {
- if (flag_is_set(DOING_DRAG))
- {
- shadow_drawable shadow_d;
- shadow_d = new shadow_drawable(d,x_offset(),y_offset());
- shadow_d.set_expensive_draw(expensive_draw());
-
- draw_children(shadow_d);
- draw_children(d);
- }
- else
- {
- draw_children(d);
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Catch damage from our children and make it bigger to account for the
- * shadow.
- *
- * @param top_left top-left corner of damage area (in our coords)
- * @param sz size of damage area
- */
- public void damage_from_child(Point top_left, Dimension sz)
- {
- int px, py;
- Point new_pt;
- Dimension larger_sz;
-
- /* expand the size to include extra for the shadow */
- larger_sz = new Dimension(sz.width + Math.abs(_x_offset),
- sz.height+ Math.abs(_y_offset));
-
- /* if this was negative, move top & left edges */
- if (_x_offset < 0)
- px = top_left.x + _x_offset;
- else
- px = top_left.x;
- if (_y_offset < 0)
- py = top_left.y + _y_offset;
- else
- py = top_left.y;
- new_pt = new Point(px,py);
-
-
- /* let the superclass do the rest */
- super.damage_from_child(new_pt, larger_sz);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-